<?php
/**
 * Created by PhpStorm.
 * User: gc
 * Date: 2018/1/10
 * Time: 20:32
 */

namespace Builder;
use Builder\ItemInter;

class Meal
{
    /**
     * @var array 食物item列表
     */
    private $lists = [];

    /**
     * 添加食物
     * @param \Builder\ItemInter $item
     */
    public function addItem(ItemInter $item) {
        $this->lists[] = $item;
    }

    /**
     * 总价
     * @return float
     */
    public function getCost() {
        $cost = 0.0;
        foreach ($this->lists as $list) {
            $cost += $list->price();
        }
        return $cost;
    }

    /**
     * 打印所有食物
     */
    public function showItems() {
        foreach ($this->lists as $list) {
            echo 'Item:' . $list->name();
            echo 'Packing:' . $list->packing()->pack();
            echo 'Price' . $list->price() . "\r\n";
        }
    }


}